import store from '@/store'
import { listSpecialType } from '@/api/qualityManage/checkType'

function searchDictByKey(dict, key) {
  if (key == null || key == '') return null
  return dict.find(i => i.key == key)?.value || null
}

// 专业类别
const specialTypeKey = 'custom_special_type'
export const getSpecialTypes = async () => {
  const storeDict = searchDictByKey(store.getters.dict, specialTypeKey)
  if (storeDict) return storeDict

  const res = await listSpecialType()
  const data = res.data
  data.map(i => {
    i.label = i.fnameL2
    i.value = i.fid
    i.listClass = '' // 去除 tag 样式
    i.raw = { ...i }
  })
  store.dispatch('dict/setDict', { key: specialTypeKey, value: data })
  return data
}
